Skip to content

fix: inherit HideHelpCommand in subcommands - #2395

Merged
dearchap merged 3 commits into
urfave:mainfrom
utkarshalpha:fix/hide-help-command-inheritance
Aug 16, 2026
Merged

fix: inherit HideHelpCommand in subcommands#2395
dearchap merged 3 commits into
urfave:mainfrom
utkarshalpha:fix/hide-help-command-inheritance

Conversation

@utkarshalpha

Copy link
Copy Markdown
Contributor

What type of PR is this?

  • bug

What this PR does / why we need it:

  • Makes HideHelpCommand inherit through the command hierarchy, matching the existing behavior of HideHelp.
  • Prevents nested commands from re-adding the built-in help command when an ancestor disabled it.
  • Extends the existing test through two nested command levels while confirming --help remains available.

Which issue(s) this PR fixes:

Fixes #2129

Testing

  • go test ./... -count=1
  • go run scripts/build.go generate
  • go run scripts/build.go vet
  • go run scripts/build.go check-binary-size
  • go run scripts/build.go gfmrun

Release Notes

Make HideHelpCommand apply to nested subcommands.

@utkarshalpha
utkarshalpha requested a review from a team as a code owner July 26, 2026 17:16

@dearchap dearchap left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed the change. Looks correct — the new test fails without the fix and passes with it, and test suite/vet/gofmt are clean. Two notes below (one behavior change to confirm, one minor doc touch-up).

Comment thread command_setup.go
if !cmd.hideHelp() {
if cmd.Command(helpCommand.Name) == nil {
if !cmd.HideHelpCommand {
if !cmd.hideHelpCommand() {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Heads-up: this is a behavior change for nested trees, not just a bug fix. hideHelpCommand() walks the whole ancestor chain, so once any ancestor sets HideHelpCommand: true, a descendant cannot re-enable the built-in help command — even by explicitly setting HideHelpCommand: false on itself. Before this change, app config help still worked when only the root hid the command, because each command's own field value controlled the append. If that was intentional (matching HideHelp inheritance semantics), consider noting it explicitly in the release notes.

Comment thread command_setup.go
return false
}

func (cmd *Command) hideHelpCommand() bool {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor: with this change HideHelpCommand now propagates to all descendants, but its doc comment in command.go still reads // Ignored if HideHelp is true. only. A short note that the value applies to this command and its subcommands would prevent confusion about why a nested command lost its help command.

The field now behaves like HideHelp: a true value applies to the whole
subtree and a subcommand cannot turn it back off. Say so on the field and
pin both halves of that behaviour with tests, so the shared semantics are
not lost again.
@utkarshalpha

utkarshalpha commented Aug 15, 2026

Copy link
Copy Markdown
Contributor Author

Yes, that's intentional. HideHelp already works this way, it walks up the parent chain, so a subcommand setting HideHelp: false under a hidden root doesn't get help back either. This just makes HideHelpCommand behave the same as HideHelp.

I added two tests for it so it doesn't get flipped back by accident later.

Doc comment updated as you asked. I also had to update godoc-current.txt and testdata/godoc-v3.x.txt, since CI compares those against the source.

For the release note, maybe something like: HideHelpCommand is now inherited by subcommands, same as HideHelp. If a command sets it, the help command is hidden for that command and everything under it.

@dearchap dearchap left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. The fix is correct: hideHelpCommand() mirrors hideHelp() by walking the parent chain, and the parent pointers are guaranteed to be set before ensureHelp() runs for any subcommand (setupDefaults sets direct children parents before ensureHelp; setupCommandGraph uses a pre-order Walk). Verified locally: full suite + race pass, vet/gofmt clean, generated godoc matches the updated godoc-current.txt and testdata/godoc-v3.x.txt.

@dearchap
dearchap merged commit 79f8fc7 into urfave:main Aug 16, 2026
9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

HideHelpCommand issues

2 participants